package com.yanqu.road.server.manger.activity.recycle;

import com.yanqu.road.entity.activity.ActivityInfo;
import com.yanqu.road.entity.activity.ActivityItemRecycleData;
import com.yanqu.road.entity.config.goods.GoodsInfo;
import com.yanqu.road.entity.enums.eActivityType;
import com.yanqu.road.entity.enums.eGoodsType;
import com.yanqu.road.entity.enums.eMailType;
import com.yanqu.road.entity.player.UserBagItem;
import com.yanqu.road.server.logic.mail.MailManager;
import com.yanqu.road.server.manger.MultipleLanguageMgr;
import com.yanqu.road.server.manger.activity.ActivityMgr;
import com.yanqu.road.server.manger.activity.springdinner.SpringDinnerMgr;
import com.yanqu.road.server.manger.config.GoodsMgr;
import com.yanqu.road.server.manger.player.UserMgr;
import java.util.ArrayList;
import java.util.List;

public class MeiTuanDaiJinQuanRecycleStrategy extends AbstractItemRecycleStrategy {
    @Override
    public void markNeedRecycleItem() {
        ActivityInfo activityInfo = SpringDinnerMgr.getActivityInfo();
        if (activityInfo != null) {
            List<GoodsInfo> infos = GoodsMgr.getGoodsListByType(eGoodsType.MeiTuanQuan.getValue());
            for (GoodsInfo goodsInfo : infos) {
                List<String> paramList = new ArrayList<>();
                long recycleTime = activityInfo.getEndShowTime() * 1000L;
                paramList.add(activityInfo.getActivityName());
                ActivityItemRecycleMgr.addRecycleItemData(goodsInfo.getGoodsId(), activityType, 1, recycleTime, paramList);
            }
        }
    }

    @Override
    public boolean isActivityRunning() {
        ActivityInfo activityInfo = SpringDinnerMgr.getActivityInfo();
        return ActivityMgr.activityInTime(activityInfo);
    }

    @Override
    protected void initActivityType() {
        activityType = eActivityType.SpringDinner.getValue();
    }

    @Override
    protected void doRecycle(long userId, ActivityItemRecycleData data) {
        String language = UserMgr.getUserInfo(userId).getLanguage();
        int goodsId = data.getItemId();
        UserBagItem userBagItem = getUserBagItem(userId, goodsId);
        if (null == userBagItem || userBagItem.getNum() <= 0) {
            return;
        }
        if (removeItem(userBagItem)) {//回收
            String mailTitle = MultipleLanguageMgr.getContent(MailManager.MEITUANDINNER_MAIL_TITLE_2, language);
            String mailContent = MultipleLanguageMgr.getContent(MailManager.MEITUANDINNER_MAIL_CONTENT_2, language);
            MailManager.sendMail(userId, eMailType.SYSTEM.getValue(), "", mailContent, mailTitle);
        } else {
            if (userBagItem.getNum() > 0) {
                log.error("remove error,consume goodsId:{},count:{}", goodsId, userBagItem.getNum());
            }
        }
    }
}
